#include "FastLED.h"
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <FS.h>

// ----------------------------------------------------------------//
// ----------------------------------------------------------------//
// ---------------------OPERATING PARAMETERS-----------------------//
// ---------------------OPERATING PARAMETERS-----------------------//
// ---------------------OPERATING PARAMETERS-----------------------//
// ----------------------------------------------------------------//
// ----------------------------------------------------------------//
#define NUM_LEDS 43
#define DATA_PIN 16//0不行
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
#define KEY_MODE 0
#define KEY_TYPE 4
#define KEY_NEXT 5
#define KEY_PREVIEW 9

#define MaxValue 255 // for hsv
#define MinValue 50  // for hsv

enum Control_type
{
  SINGLE,
  CIRCULATION,
  RANDOM,
  INVALID
};

enum Gradient_type
{
  DOWN,
  UP
};
enum Hightolow_type
{
  GRADIENT,
  DROP
};

enum Mode
{
  Skyarrow_Single,
  Skyarrow_Color,
  Bloom,
  Launch_Bg,
  Launch_Cs,
  Launch_As,
  Rainbowgradient,
  Fivepointflow,
  Breath,
  InvalidMode
};

uint8_t HUE[NUM_LEDS] = {};
uint8_t BRIGHT[NUM_LEDS] = {};

bool isMODEModified = false;
bool isTimerOn = false;

uint8_t min_bright = 0;
uint8_t max_bright = 128; //
uint8_t Delay_Time = 30;  //
uint8_t bright = max_bright;
uint8_t hue[6] = {};

Control_type control_type = CIRCULATION; //
Mode mode = Rainbowgradient;             //

CRGB leds[NUM_LEDS];
// ----------------------------------------------------------------//
// -------------------------SELF DEFINE----------------------------//
// ----------------------------------------------------------------//
#include "wifi.h"
#include "timer.h"
#include "function.h"
// ----------------------------------------------------------------//
// ----------------------------SETUP-------------------------------//
// ----------------------------------------------------------------//
void setup()
{
  // Infinite the serial
  Serial.begin(115200);
  delay(500);
  // set WS2812 light belt
  LEDS.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS); // Infinite light belt
  FastLED.setBrightness(bright);                                 // set max setBrightness

  // start fs system
  if (SPIFFS.begin())
    Serial.println("SPIFFS Started.");
  else
    Serial.println("SPIFFS Failed to Start.");

  // Infinite webserver
  Webctrl.connect("zhouliangan44", "wxg13948532823");
  Webctrl.beginserver();

  // welcoming mode
  skyarrow_single();
  Brightctrl.gradient(DOWN);

  // SET KEY
  pinMode(KEY_MODE, INPUT_PULLUP);
  pinMode(KEY_TYPE, INPUT_PULLUP);
  pinMode(KEY_NEXT, INPUT_PULLUP);
  pinMode(KEY_PREVIEW, INPUT_PULLUP);

  delay(1000);
  // Serial.println(" ");
  // Serial.println("now is skyarrow_color");
  // skyarrow_color();  //
  // Serial.println("now is breath");
  // Brightctrl.breath();
  // Serial.println("fivepointflow");
  // fivepointflow();  //
  // Serial.println("bloom");
  // bloom(100);  //
}

// ----------------------------------------------------------------//
// -----------------------------LOOP-------------------------------//
// ----------------------------------------------------------------//

void loop()
{
  Serial.println("loop");
  play();
}
